#!/bin/bash


NAME=
PASS=
DOMAIN=
QS=qshell
DEBUG=

if [ "${NAME}" == "" ] || [ "${PASS}" == "" ] || [ "${DOMAIN}" == "" ] || [ "${QS}" == "" ]; then
    echo "Please Config First"
    exit 1
fi

FOLDER=$1

if [ "${FOLDER}" == "" ]; then
  echo "No Folder!!"
  echo "Usage: $0 区域 本地上传的文件夹/文件名地址"
  exit 2
fi


PREFIX=$2

if [ "${PREFIX}" == "" ]; then
	echo "Usage: $0 区域 本地上传的文件夹/文件名地址"
else
	if [ "${PREFIX:0-1}" != "/" ]; then
	  PREFIX=${PREFIX}/
	fi
fi

chmod +x ${QS}

# 检测环境
${QS} -v

# 授权
${QS} account ${NAME} ${PASS}

# 查看服务器内容
${QS} buckets
${QS} domains ${DOMAIN}


# qshell fput domain target source
if [ "${DEBUG}" == "" ]; then
	python $(cd `dirname $0`; pwd)/list.py ${FOLDER} | xargs -I {} ${QS} fput momoda-game-res ${PREFIX}{} {}
else
	python $(cd `dirname $0`; pwd)/list.py ${FOLDER} | xargs -I {} echo ${QS} fput momoda-game-res ${PREFIX}{} {}
fi
